<?php

if (!defined('BASEPATH'))
	exit('No direct script access allowed');

/**
 * Init Model
 *
 */


class Banner_model extends CI_Model {

	function __construct(){
		parent::__construct();
	}


	//--show = 1: index Page 2: inner page
	function getBanner($show=2, $limit=5, $max_clicks=0, $max_impression=0){
		
		
		
		if($show == 2 ){
			$sql = "select * from banner where (clicks < max_clicks and impressions < max_impressions or max_clicks = 0 or max_impressions = 0) and shows = $show and status=51 or shows = 0 limit $limit ";
		}
		
		if($show == 1 ){
			$sql = "select * from banner where (clicks < max_clicks and impressions < max_impressions or max_clicks = 0 or max_impressions = 0) and shows = $show and category = 0 and status=51 or shows = 0 order by id DESC limit $limit";
		}
		
		//print $sql;
		$result = $this->db->query($sql)->result();

		if($result){
			return $result;
		}else{
			return false;
		}
	}
	
	
	function getbnnrcat($cat_id = NULL)
	{
		$sql = "Select *from banner where category=$cat_id and status=51 order by id desc limit 3";
		$query = $this->db->query($sql);
		$result = $query->result();
		return $result;
	}
	
	function getslider($show=4, $limit=4)
	{
	
		$sql = "Select *from banner where shows = $show and status=51 order by id asc limit 4";
		$query = $this->db->query($sql);
		$result = $query->result();
		return $result;
		
	}
}
/* End of file*/
